package com.toubutu.audio.admin.controller;

import com.toubutu.audio.admin.dto.PermissionDto;
import com.toubutu.audio.admin.dto.RoleBindPermissionVo;
import com.toubutu.audio.admin.service.PermissionService;
import com.toubutu.audio.admin.vo.PermissionVo;
import com.toubutu.audio.common.PermissionCode;
import com.toubutu.common.Result;
import com.toubutu.permission.Permission;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 戒燥
 * @since 2023-09-30
 */

@RequestMapping("/admin/permission")
@Api(tags = "后台管理-权限管理接口")
@RestController
public class PermissionController {

    @Resource
    private PermissionService permissionService;

    @GetMapping("/role/tree")
    @ApiOperation("获取菜单绑定树形结构")
    public Result<List<RoleBindPermissionVo>> getRoleBindMenuTree(){
        return Result.ok(permissionService.getMenuForRoleBindTree());
    }



    @GetMapping("/tree")
    @ApiOperation("获取权限树形结构")
//    @Permission(PermissionCode.Permission.PERMISSION_LIST)
    public Result<List<PermissionVo>> getMenuTree(){
        return Result.ok(permissionService.getPermissionTree());
    }

    @GetMapping("/info/{permissionId}")
    @ApiOperation("获取权限信息")
//    @Permission(PermissionCode.Permission.PERMISSION_DETAIL)
    public Result<PermissionVo> getMenuInfoById(@PathVariable Integer permissionId){
        return Result.ok(permissionService.getPermissionInfo(permissionId));
    }

    @PostMapping("/add")
    @ApiOperation("添加权限")
//    @Permission(PermissionCode.Permission.PERMISSION_ADD)
    public Result<Boolean> addMenu(@RequestBody PermissionDto permissionDto){
        return Result.ok(permissionService.addPermission(permissionDto));
    }
    @PostMapping("/update")
    @ApiOperation("修改权限信息")
//    @Permission(PermissionCode.Permission.PERMISSION_UPDATE)
    public Result<Boolean> updatePermission(@RequestBody PermissionDto permissionDto){
        return Result.ok(permissionService.updatePermission(permissionDto));
    }

    @DeleteMapping("/delete/{permissionId}")
    @ApiOperation("删除权限信息")
//    @Permission(PermissionCode.Permission.PERMISSION_DELETE)
    public Result<Boolean> deleteMenu(@PathVariable Integer permissionId){
        return Result.ok(permissionService.deletePermission(permissionId));
    }
}
